<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box ;
        }
        .box {
            margin-top: 50px;
        }

        .form {
            padding: 20px 10px;
            background-color: #eeeeee;
            margin-top: 20px;
        }
        ul{
            list-style: none;
        }
        li{
            padding: 20px 30px;
            background-color: #cccc;
            margin: 20px 0px;
        }
    </style>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>

<body>
    <div id="app" class="container box" @keyup.9="gettab">

        <button  class="btn" :class="tag?'btn-default':'btn-primary'">评论管理</button>
        <button  class="btn" :class="tag?'btn-primary':'btn-default'">发布评论</button>


        <div v-show="tag" class="form-horizontal form">

            <div class="form-group">

                <div class="col-sm-10">
                    <input type="text" v-model="xingxi.user" class="form-control" placeholder="昵称">
                </div>
            </div>
            <div class="form-group">

                <div class="col-sm-10">
                    <input type="text" v-model="xingxi.text" class="form-control" placeholder="评论内容">
                </div>
            </div>

            <div class="form-group">
                <div class=" col-sm-10">
                    <button @click="getpl" class="btn btn-primary">立即提交</button>
                </div>
            </div>
        </div>
        <ul v-show="!tag">
            <li v-for="item in mydata">
                <p>评论人：{{item.user}}</p>
                <p>评论内容：{{item.text}}</p>
                <p>评论时间：{{item.time}}</p>
            </li>
        </ul>

    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script> -->
    <script>
        // $(document).ready(function () {
        //     $(document).bind('keydown', function (event) {
        //         if (event.keyCode == 9) {
        //             return false;
        //         }
        //     });
        // });
        new Vue({
            el: '#app',
            data: {
                tag: true,
                mydata: [
                    {
                       
                        user: 'as',
                        text: 'as',
                        time: new Date().toLocaleDateString()
                    }
                ],
                xingxi: {
                    user: '',
                    text: '',
                }
            },
            methods: {
                gettab(ev) {
                    console.log(ev.key);
                    this.tag = !this.tag

                },
                getpl() {

                    let obj = {
                        ...this.xingxi,
                        time: new Date().toLocaleDateString()
                    }
                    // console.log(obj);
                    this.mydata.push(obj)
                    console.log(this.mydata);
                }
            },

        })
    </script>
</body>

</html>